<?php

/**
 * Galeria form.
 *
 * @package    form
 * @subpackage Galeria
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
 */
class GaleriaForm extends BaseGaleriaForm
{
  	public function configure()
  	{
  		parent::configure();
		
  		$this->widgetSchema['nm_galeria'] = new sfWidgetFormInput(
			array(),
			array('class' => 'required', 'size' => '100', 'maxlength' => '80')
		);
		
		$options = array('S'=>'Sim', 'N'=>'Não');
		$this->widgetSchema['st_galeria'] = new sfWidgetFormChoice(
			array('choices'=>$options, 'expanded'=>true, 'multiple'=>false)
		);
		
		$this->widgetSchema['ds_item'] = new sfWidgetFormTextarea(
			array(),
			array(	
				'cols' => 70,
				'rows' => 6
            )
        );
		
  		/*
       	 * Formulário embutido de mídia
       	 */
      	$form = new MidiaGaleriaForm(null, array(
			'item' => $this->getObject(),//nome do objeto
			'size'    => 10 //quantidade de registros
		));
        $this->embedForm('midia', $form);
  		
  		$this->widgetSchema->setLabels(array(
  	      	'id_galeria' => 'ID#',
	      	'nm_galeria' => 'Nome',
	      	'ds_galeria' => 'Descrição',
	      	'st_galeria' => 'Publicado',
	      	'slug'       => 'Slug',
	      	'created_at' => 'Criado em',
	      	'updated_at' => 'Alterado em',
		));
  	}
  	
	public function saveEmbeddedForms($con = null, $forms = null)
	{
		if (null === $forms)
		{
			$midia = $this->getValue('midia');
			$forms = $this->embeddedForms;
			foreach ($this->embeddedForms['midia'] as $name => $form)
			{
				if (!isset($midia[$name]))
					unset($forms['midia'][$name]);
			}
		}
		parent::saveEmbeddedForms($con, $forms);
		 
		//Criando as Thumbs
		foreach($this->getObject()->getMidia() as $midia)
		{
			$thumb   = new Midia();
			$thumb->createThumb($midia);
		}

		return;
	}
}